package com.mes.task.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;
import com.mes.inventory.domain.InvIO;
import com.mes.inventory.domain.Material;

/**
 * <p>
 * TaskMaterial实体，记录任务所利用到的物料。
 * </p>
 */
@Entity()
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name = "T_TASK_MATERIAL")
@BatchSize(size = 30)
@Lazy(value = true)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TaskMaterial extends BasicModel {
	
	public static long CHANGETYPE_LOTSPLIT_TASK = 6;
	public static long CHANGETYPE_LOTMERGE_TASK = 7;
	public static long CHANGETYPE_LOTSPLIT_QUALITY = 4;
	public static long CHANGETYPE_LOTMERGE_QUALITY = 5;
	public static long CHANGETYPE_ASSEMBLY = 1;
	public static long CHANGETYPE_SPLIT = 2;
	public static long CHANGETYPE_CONSUME = 3;

	// 唯一号
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUEID", scale = 0)
	private String uniqueId;

	@Column(name = "TASKUID")
	protected String taskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
	protected OperationTask operationTask;

	@Column(name = "INMATERIALUSN")
	protected String inMaterialUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "INMATERIALUSN", insertable = false, updatable = false)
	protected Material inMaterial;

	@Column(name = "INMATERIALQTY")
	protected Double inMaterialQty;

	@Column(name = "OUTMATERIALUSN")
	protected String outMaterialUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "OUTMATERIALUSN", insertable = false, updatable = false)
	protected Material outMaterial;

	@Column(name = "OUTMATERIALQTY")
	protected Double outMaterialQty;

	@Column(name = "INVIOID")
	protected String invIOUid;
	/**
	 * 复杂对象映射--invio
	 */
	@Transient
	protected InvIO invIO;

	@Column(name = "CHANGETYPE")
	protected Long changeType;
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "TASKTYPE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'changetype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData changeTypeDesc;

	@Column(name = "CHANGESTATE")
	protected Long changeState;
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "TASKTYPE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'changestate'", referencedColumnName = "TYPESNAME")) })
	protected TypesData changeStateDesc;

	/**
	 * 待料单号
	 */
	@Column(name = "RMUID")
	protected String replaceMaterialBillId;

	/**
	 * 空的构造函数
	 */
	public TaskMaterial() {
	}

	/**
	 * 获取任务Uid
	 * 
	 * @return
	 */

	public String getTaskUid() {
		return taskUid;
	}

	/**
	 * 设置任务Uid
	 * 
	 * @param taskUid
	 */
	public void setTaskUid(String taskUid) {
		this.taskUid = taskUid;
	}

	/**
	 * 获取任务对象
	 * 
	 * @return
	 */

	public OperationTask getOperationTask() {
		return operationTask;
	}

	/**
	 * 设置任务对象
	 * 
	 * @param task
	 */
	public void setOperationTask(OperationTask operationTask) {
		this.operationTask = operationTask;
	}

	/**
	 * 获取收料Uid
	 * 
	 * @return
	 */

	public String getInMaterialUid() {
		return inMaterialUid;
	}

	/**
	 * 设置收料Uid
	 * 
	 * @param inMaterialUid
	 */
	public void setInMaterialUid(String inMaterialUid) {
		this.inMaterialUid = inMaterialUid;
	}

	/**
	 * 获取收料对象
	 * 
	 * @return
	 */

	public Material getInMaterial() {
		return inMaterial;
	}

	/**
	 * 设置收料对象
	 * 
	 * @param inMaterial
	 */
	public void setInMaterial(Material inMaterial) {
		this.inMaterial = inMaterial;
	}

	/**
	 * 获取出料Uid
	 * 
	 * @return
	 */

	public String getOutMaterialUid() {
		return outMaterialUid;
	}

	/**
	 * 设置出料Uid
	 * 
	 * @param outMaterialUid
	 */
	public void setOutMaterialUid(String outMaterialUid) {
		this.outMaterialUid = outMaterialUid;
	}

	/**
	 * 获取出料对象
	 * 
	 * @return
	 */

	public Material getOutMaterial() {
		return outMaterial;
	}

	/**
	 * 设置出料对象
	 * 
	 * @param outMaterial
	 */
	public void setOutMaterial(Material outMaterial) {
		this.outMaterial = outMaterial;
	}

	/**
	 * 获取变更类型
	 * 
	 * @return
	 */

	public Long getChangeType() {
		return changeType;
	}

	/**
	 * 设置变更类型
	 * 
	 * @param changetype
	 */
	public void setChangeType(Long changeType) {
		this.changeType = changeType;
	}

	/**
	 * 获取变化类型，1、装配，2、拆分 3、消耗 4、质量分批 5、质量合批
	 * 
	 * @return
	 */

	public TypesData getChangeTypeDesc() {
		return changeTypeDesc;
	}

	/**
	 * 设置变化类型，1、装配，2、拆分 3、消耗 4、质量分批 5、质量合批
	 * 
	 * @param changetypeDesc
	 */
	public void setChangeTypeDesc(TypesData changeTypeDesc) {
		this.changeTypeDesc = changeTypeDesc;
	}

	/**
	 * 获取收料数量
	 * 
	 * @return
	 */

	public Double getInMaterialQty() {
		return inMaterialQty;
	}

	public void setInMaterialQty(Double inMaterialQty) {
		this.inMaterialQty = inMaterialQty;
	}

	/**
	 * 设置收料数量
	 * 
	 * @param inMaterialqty
	 */
	public void setInmaterialQty(Double inMaterialQty) {
		this.inMaterialQty = inMaterialQty;
	}

	/**
	 * 获取出料数量
	 * 
	 * @return
	 */

	public Double getOutMaterialQty() {
		return outMaterialQty;
	}

	/**
	 * 设置出料数量
	 * 
	 * @param outMaterialQty
	 */
	public void setOutMaterialQty(Double outMaterialQty) {
		this.outMaterialQty = outMaterialQty;
	}

	/**
	 * 获取创建者
	 * 
	 * @return
	 */

	public Employee getCreator() {
		return creator;
	}

	/**
	 * 设置创建者
	 * 
	 * @param creator
	 */
	public void setCreator(Employee creator) {
		this.creator = creator;
	}

	/**
	 * 获取出入库单号
	 * 
	 * @return
	 */

	public String getInvIOUid() {
		return invIOUid;
	}

	/**
	 * 设置出入库单号
	 * 
	 * @param invIOUid
	 */
	public void setInvIOUid(String invIOUid) {
		this.invIOUid = invIOUid;
	}

	/**
	 * 获取出入库单据对象
	 * 
	 * @return
	 */

	public InvIO getInvIO() {
		return invIO;
	}

	/**
	 * 设置出入库单据对象
	 * 
	 * @param invIO
	 */
	public void setInvIO(InvIO invIO) {
		this.invIO = invIO;
	}

	/**
	 * 获取分批状态
	 * 
	 * @return
	 */

	public Long getChangeState() {
		return changeState;
	}

	/**
	 * 设置分批状态
	 * 
	 * @param changestate
	 */
	public void setChangeState(Long changeState) {
		this.changeState = changeState;
	}

	/**
	 * 获取分批状态，0表示未完成任务分批，1表示已经完成任务分批
	 * 
	 * @return
	 */

	public TypesData getChangeStateDesc() {
		return changeStateDesc;
	}

	/**
	 * 设置分批状态，0表示未完成任务分批，1表示已经完成任务分批
	 * 
	 * @param changeStateDesc
	 */
	public void setChangeStateDesc(TypesData changeStateDesc) {
		this.changeStateDesc = changeStateDesc;
	}

	/**
	 * 获取待料单编号
	 * 
	 * @return
	 */

	public String getReplaceMaterialBillId() {
		return replaceMaterialBillId;
	}

	/**
	 * 设置待料单编号
	 * 
	 * @param rmuid
	 */
	public void setReplaceMaterialBillId(String replaceMaterialBillId) {
		this.replaceMaterialBillId = replaceMaterialBillId;
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.uniqueId;
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.uniqueId = uuid;
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

}
